﻿using System;
using System.Data.Services;
using System.Data.Services.Common;
using System.Diagnostics;
using Service.Model;

namespace Service
{
	public class Federation : DataService<ServiceModel>
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
			if (config == null)
				throw new ArgumentException("config");

            config.SetEntitySetAccessRule("*", EntitySetRights.All);
			config.SetServiceOperationAccessRule("*", ServiceOperationRights.AllRead);

            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
			config.DataServiceBehavior.AcceptProjectionRequests = true;

        	config.UseVerboseErrors = true;
        }

		protected override void HandleException(HandleExceptionArgs args)
		{
			var ex = args.Exception;

			Trace.Write(ex);

			if (!(ex is DataServiceException))
				args.Exception = new DataServiceException(500, null, ex.Message, null, ex);

			base.HandleException(args);
		}
    }
}
